home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / networking / short_timeout / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.9 KB  |  62 lines

  1. /*
  2.  * Copyright 1994, Silicon Graphics, Inc. 
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or 
  7.  * duplicated in any form, in whole or in part, without the prior written 
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions 
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or 
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - 
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*
  19.  *  main.c contains only the main() function of hrq, a command line wrapper
  20.  *  around function host_responds_quickly.  hrq is essentially a no-frills
  21.  *  version of ping, but one in which the timeout period is mercifully brief.
  22.  *  hrq prints an advisory about whether the host whose name is given as the
  23.  *  only command line argument responds to an ICMP echo request before a
  24.  *  short timer expires.  It sets its exit status to 1 if the host does not
  25.  *  respond quickly, to 0 if it does respond quickly, and to a negative number
  26.  *  if there is some error.
  27.  *
  28.  *  Program hrq needs to be installed setuid to root.
  29.  *
  30.  *  Author:  Aaron Schuman
  31.  */
  32.  
  33. #include <stdio.h>
  34. #include "hrq.h"
  35.  
  36. main( int argc, char * argv[] )
  37. {
  38.     int    response;
  39.     char *    errmsg;
  40.  
  41.     if ( 2 != argc )
  42.     {
  43.         fprintf( stderr, "Usage: %s host\n", argv[0] );
  44.         exit( -1 );
  45.     }
  46.  
  47.     response = host_responds_quickly( argv[1] );
  48.  
  49.     if ( 0 > response )
  50.     {
  51.         fprintf( stderr, "%s error \"%s\"; hostname = %s\n",
  52.             "host_responds_quickly", hrqerr( response ), argv[1] );
  53.         exit( response );
  54.     }
  55.  
  56.     printf( "Reply %s received from %s\n",
  57.         QUICK_RESPONSE == response ? "was" : "not", argv[1] );
  58.  
  59.     exit( response );
  60. }
  61.  
  62.